<template>
  <el-radio-group
    :clearable="sClearable"
    :disabled="disabled"
    :class="sClass"
    v-model="svalue"
    sPlaceholder="全部"
    @change="sChange"
    @click="childMethod"
    style="width:98%;padding:0px 0px 8px 10px;"
  >
<!-- label	Radio 的 value -->
    <el-radio
      v-for="dict in distList"
      :key="dict.dictValue"
      :label="dict.dictValue"
      :value="dict.dictLabel"
    >{{dict.dictLabel}}</el-radio>
  </el-radio-group>

</template>

<script>
  export default {
    name:'commonRadio',
    props: {
      value: {
        type: [String],
      },
      distType: {
        type: String,
        required: true
      },
      keys: {
        type: String,
        default: ""
      },
      label: {
        type: String,
        default: "Text"
      },
      option: {
        type: String,
        default: "Value"
      },
      sClass: {
        type: String,
        default: "querySelect"
      },
      sClearable: {
        type: Boolean,
        default: true
      },
      sPlaceholder: {
        type: String,
        default: "全部"
      },
      disabled: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        distList: [],
        svalue: this.value
      };
    },
    created() {
      this.getDist(this.distType);
    },
    methods: {
      sChange() {
        this.$emit("sChange");
      },
      getDist(type) {
        this.getDicts(type).then(response => {
          this.distList = response.data
        })
      }
    },
    watch: {
      value(newVal) {
        this.svalue = newVal;
      },
      /*
      调用子组件方法
       */
      childMethod() {
        this.$emit('fatherMethod');
      },
      svalue(newVal, oldVal) {
        if (newVal !== oldVal) {
          this.$emit("input", this.svalue);
        }
      }
    }
  };
</script>
